<template>
  <div>
    <el-dialog :visible.sync="visible" width="500px" :title="$tt('label_batch_operate')">
      <el-form ref="form" :model="form" :rules="rules" label-width="120px">
        <el-form-item :label="$tt('label_sku_return_method')" prop="skuReturnMethod">
          <ex_super_input v-model="form.skuReturnMethod" type="select" enum="SkuReturnMethodEnum" class="w_fill" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="visible = false">{{ $tt('label_cancel') }}</el-button>
        <el-button type="primary" @click="sumbit">{{ $tt('label_confirm') }}</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
export default {
  data() {
    return {
      visible: false,
      form: {
        skuReturnMethod: null
      },
      rows: [],
      rules: {
        skuReturnMethod: { required: true, message: this.$tt('tip_can_no_empty'), trigger: 'blur' },
      },
    }
  },

  methods: {
    show(rows) {
      this.rows = _.cloneDeep(rows)
      this.rows.forEach(it => it.skuReturnMethod = null)
      this.visible = true
    },
    sumbit() {
      if (this.$clickFast()) return
      this.$refs['form'].validate((valid, obj) => {
        if (valid) {
          let list = this.rows.map((item) => {
            return {
              id: item.id,
              skuReturnMethod: this.form.skuReturnMethod
            }
          })
          this.$ajax({
            url: this.$url['mms/skuBatchUpdate'],
            type: 'json',
            data: {
              skuUpdateList: list
            },
            success: (responseData) => {
              this.$message({
                showClose: true,
                message: this.$tt('tip_submit_success'),
                type: 'success'
              })
              this.visible = false
            }
          });
        } else {
          this.$message.error(this.$tt('form_validate_error'))
          return false;
        }
      });
    }

  }

}

</script>

<style scoped>
.el-dropdown-link {
  cursor: pointer;
}

.el-icon-arrow-down {
  font-size: 12px;
}
</style>
